package be.tf.freemaind.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import be.tf.freemaind.service.TreeGenerator;

import com.mysql.jdbc.Statement;

/**
 * Servlet implementation class TreeMapServlet
 */
public class TreeMapServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		TreeGenerator treeGenerator = new TreeGenerator();
		Statement stm = (Statement) this.getServletContext()
				.getAttribute("stm");
		String map = treeGenerator.xmlMap(stm);
		//System.out.println(map);
		
		response.setContentType("application/xml");
		PrintWriter out = response.getWriter();
		out.append(map);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
